//https://www.bilibili.com/video/BV1d54y1f7B3/?spm_id_from=333.337.search-card.all.click&vd_source=d6fe65f095f01f05591e89d810720ccc
// 2024-10-18


import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class P010_无序数组两数之和_空间换时间 {

    public static void main(String[] args) {
        System.out.println(Arrays.toString(fun(new int[]{1, 2, 3, 4, 5, 6}, 10)));
    }

    private static int[] fun(int[] nums,int target) {
        Map<Integer,Integer> map = new HashMap<>(); //关键,通过map打标记
        for (int i = 0;i < nums.length;i++) {
            if (map.containsKey(target - nums[i]))
                return new int[] {map.get(target - nums[i]),i};
            map.put(nums[i], i);
        }
        return null;
    }
}
